Repository navigation
Reentry simulation: simulated parts no longer write into KSP's global lift and drag curves - #2799
Merged
Merged
Conversation
…no longer KSP's global ones DragCubeList.SetPart, called for each simulated part's cube list, points the list at the global PhysicsGlobals.BodyLiftCurve and PhysicsGlobals.SurfaceCurves, and SimCurves.CopyTo then wrote the simulation's curve copies into them. So every prediction replaced KSP's global body lift and surface drag curves with one simulation's copies, and KSP's physics on the main thread and the next simulation on its thread evaluated the same AnimationCurves at once. Both read garbage, often 0: in flight, half the predictions of a lifting capsule had no body lift and landed 20 km short of the others, and stock's own curve read 0 on the main thread. The cube list now gets the part's own containers back after SetPart (the pool's Create gave it some, which SetPart replaced at once; SimulatedParachute's pool never did).
Contributor
✅ Build Artifact 🚀MechJeb2-f41199a.zip (built from a491d77) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The bug (on dev)
SimulatedPart.CopyDragCubesListcalls stockDragCubeList.SetPart, which points the cube list at the globalPhysicsGlobals.BodyLiftCurveandPhysicsGlobals.SurfaceCurves(DragCubeList.csSetPart).SimCurves.CopyTothen writes the simulation's curve copies into whatever the list holds:dest.BodyLiftCurve.liftCurve = _liftCurve,dest.SurfaceCurves.dragCurve* = …. So every landing prediction replaced KSP's global body lift and surface drag curves with one simulation's copies, and KSP's physics on the main thread and the next simulation on its thread pool thread evaluated the sameAnimationCurves at once. Both read garbage, often 0.The private containers
SimulatedPart's poolCreatemade were replaced bySetPartstraight away;SimulatedParachute's pool never made any.Seen in flight (MechJeb2_UI Spike 185, Kerbal X pod, Land at KSC, heat shield first at 15 deg)
PhysicsGlobals.BodyLiftCurve.liftCurveevaluated on the main thread returned 0 at dot 0.3/0.6/0.9 on those samples (0.5735/0.9597/0.7804 otherwise), and the pod's real body lift reading stayed frozen at 0.642 kN for 26 km: stock's aerodynamics were very likely affected too, for any vessel, while predictions ran (indirect: measured on that reading only).Fix
After
SetPart, the cube list gets the part's ownLiftingSurfaceCurveandSurfaceCurvesListback (fields ofSimulatedPart, so the parachute subclass has them too).DragCurveCd/DragCurveCdPower/DragCurveMultiplierwere never affected:CopyToreplaces those references, it doesn't write into them.After the fix (3 flights): 0 of 275 samples with zero simulated lift, simulated lift = stock's within 0.88-1.01x at the same attitude, no prediction jumps.
PSG ascent isn't affected directly: its solver runs on MechJebLib's managed interpolants, and AutoAero (
PSGAeroEstimate) and the atmosphere fit run on the main thread. AutoAero reads the global curves, so it could read garbage only while landing predictions ran at the same time, which this fix also ends.